#include "CareTaker.h"
#include "Memento.h"

CareTaker::CareTaker(void)
{
}

CareTaker::~CareTaker(void)
{
	clearMemento();
	clearUnusedMemento();
}

void CareTaker::pushMemento(Memento* pMem)
{
	m_list.push_front(pMem);
}

Memento* CareTaker::popMemento()
{
	if (m_list.size() > 0)
	{
		Memento* pMem = (*m_list.begin());
		m_listUnused.push_front(pMem);
		m_list.pop_front();
		return pMem;
	} 
	else
	{
		return NULL;
	}
}
void CareTaker::clearMemento()
{
	std::list<Memento*>::iterator it;
	for (it = m_list.begin();
		it != m_list.end(); ++it)
	{
		delete (*it);
	}
}

void CareTaker::clearUnusedMemento()
{
	std::list<Memento*>::iterator it;
	for (it = m_list.begin();
		it != m_list.end(); ++it)
	{
		delete (*it);
	}
}
